{% extends base.html %}

{% block head %}
<link rel="stylesheet" href="{{static_url('css/add_task.css')}}" type="text/css" media="screen" />
<style>
#addtask_head #message { float: left; margin: 7px 0 0 50px; padding: 0 5px; background-color: #ffc4c4; font-size: 13px; line-height: 23px; }
</style>
{% end %}

{% block body %}
<div id="addtask_head">
	<!--
	<span style="float:left;margin:9px 0 0 3px">
		添加任务
  </span> -->
  <span id="message">{{ message }}</span>
</div>
<div id="addtask_main">
<form class="addtask_form" method="post" enctype="multipart/form-data" onsubmit="return on_submit();">	
	<div class="addtask_up">
	<div class="l">Email</div>
	<div class="r">
		<input type="text" name="login_email" id="email" maxlength="256" value="" style="width:300px;" />
	</div>
	</div>
	
	<div class="addtask_up">
	<div class="l">name</div>
	<div class="r">
		<input type="text" name="login_name" id="name" maxlength="1024" value="" style="width:300px;" />
	</div>
	</div>
	
	<div class="addtask_button">
        <input class="button" name="b" type="submit" value="提交" />
		<button class="button" type="reset" onclick="location.reload();">重置</button>
	</div>
</form>
</div>

<div id="addtask_foot">
	<!-- 后续说明？ -->
</div>
{% end %}

{% block foot %}
<script>
function on_submit() {
  var form = document.forms[0];
  if (form.url.value == "" && from.btfile.value == "") {
    document.getElementById("message").innerText = "任务下载地址不能为空";
    return false;
  }
  form.b.value = "提交中...";
  form.b.disabled = true;
  form.tags.readOnly = true;
  form.url.readOnly = true;
  form.title.readOnly = true;
  return true;
}

function on_url_change() {
  var form = document.forms[0];
  var url = form.url;
  if (url.value != "" && (url.class == "" || url.class == undefined)) {
    url.class = "changed";
    url.style.cssText = "width: 300px; -moz-border-radius: 5px; border-radius: 5px; -webkit-border-radius: 5px;";
    document.getElementsByClassName("bt_file")[0].style.cssText = "width:0;";
  } else if (url.value == "") {
    url.class = "";
    url.style.cssText = "width: 230px;border-right:none;";
    document.getElementsByClassName("bt_file")[0].style.cssText = "";
  }
}

function on_file_change() {
  var form = document.forms[0];
  var url = form.url;
  var file = form.btfile.files[0];
  console.log(file);
  if (file) {
    if (file.size > 500*1024) {
      form.btfile.value = "";
      document.getElementById("message").innerText = "文件过大";
      return false;
    }
    if (!file.name.match(/.torrent$/i)) {
      form.btfile.value = "";
      document.getElementById("message").innerText = "需要种子文件";
      return false;
    }
  }
  document.getElementById("message").innerText = "";
  url.value = form.btfile.value;
  url.disabled = true;
  url.readOnly = true;
}
</script>
{% end %}
